﻿////////////////////////////////////////////////////////////////////
//
//	Map_FVG C# Class Library.
//
//	dlgIdentificativo
//
//	autore: Gustavo Mainardi 
//	versione: 1.0
//	data: 01/12/2015
//
//
//	Cronologia delle versioni:
//
//	Versione 1.0 01/12/2015
//		versione originale
//
//////////////////////////////////////////////////////////////////////////
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Globalization;

namespace Map_Fvg
{
    public partial class dlgIdentificativo : Form
    {
        public dlgIdentificativo()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int number;
            string value = textBox1.Text;
            bool result = Int32.TryParse(value, out number);
            if (result)
            {
                if (number >= ViewQ.nShapes)
                {
                    number = ViewQ.nShapes - 1;
                    MessageBox.Show("valore non idoneo; max = " + number.ToString());
                    return;
                }
                ViewQ.selected_linea = number;
                drawLinea(number, 0);     
                
//                ViewQ.panel1.Invalidate();
                Linea_dlg dlg = new Linea_dlg();
                DialogResult dr = dlg.ShowDialog();
    //            if (dr == DialogResult.OK)
                {
                    ViewQ.Select_flag = 1;
                    ViewQ.tipo_selezione = (int)ViewQ.flagSelez.linea;
                    this.DialogResult = DialogResult.OK;
                }
                this.Close();
  
                return;
            }
            else
            {
                if (value == null) value = "";
                MessageBox.Show("valore non idoneo");
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.No;
            this.Close();
        }

        private void drawLinea(int ipt, int opt)
        {
            char[] delimiterChars0 = { ',', '/' };
            string[] words;

            ViewQ.dc0.RotateTransform(ViewQ.alpha);

            NumberFormatInfo nfi = new CultureInfo("en-US", false).NumberFormat;

            int nVertices = ViewQ.vectShapes[ipt].nVertices;
            int ipnt = ViewQ.vectShapes[ipt].pntpL;
            int pntSimb = ViewQ.vectShapes[ipt].pntSimb;

            if (ViewQ.vectS[pntSimb].selected == 0) goto L40;
            int visib = ViewQ.vectS[pntSimb].visib;
            if (visib == 0) goto L40;

            Color icolor = new Color();
            if (opt == 1) icolor = ViewQ.vectS[pntSimb].icolor;
            else icolor = Color.Red;
            string ss = ViewQ.vectS[pntSimb].tratto;
            int type = ViewQ.vectS[pntSimb].penType;
            float width = 0F;
            float interpasso = 0F;
            float diam = 0F;
            string s1;
            float[] dashValues = { 0, 0 };

            Scarpata scr = new Scarpata();

            switch (type)
            {
                case 1:
                    int ipos = ss.IndexOf('/');
                    s1 = ss.Substring(0, ipos);
                    width = float.Parse(s1, nfi);
                    break;
                case 11:            // scarpata (ciglio)
                case 12:            // scarpata (piede)
                case 13:            // scarpata rivestita (ciglio)
                    ipos = ss.IndexOf('/');
                    s1 = ss.Substring(0, ipos);
                    words = s1.Split(delimiterChars0);
                    width = float.Parse(words[3], nfi);
                    dashValues[0] = float.Parse(words[0], nfi);
                    dashValues[1] = float.Parse(words[1], nfi);
                    interpasso = float.Parse(words[2], nfi);

                    break;
                case 26:         //  limite di bosco
                    ipos = ss.IndexOf('/');
                    s1 = ss.Substring(0, ipos);
                    words = s1.Split(delimiterChars0);
                    width = float.Parse(words[4], nfi);
                    dashValues[0] = float.Parse(words[0], nfi);
                    dashValues[1] = float.Parse(words[1], nfi);
                    diam = float.Parse(words[2], nfi);
                    interpasso = float.Parse(words[3], nfi);
                    break;
                case 33:
                    ipos = ss.IndexOf('/');
                    s1 = ss.Substring(0, ipos);
                    words = s1.Split(delimiterChars0);
                    dashValues[0] = float.Parse(words[0], nfi);
                    dashValues[1] = float.Parse(words[1], nfi);
                    width = float.Parse(words[2], nfi);
                    break;
                case 40:         //  curva di livello intermedia
                case 41:         //  curva di livello direttrice
                    ipos = ss.IndexOf('/');
                    s1 = ss.Substring(0, ipos);
                    width = float.Parse(s1, nfi);
                    break;

                case 42:     //  sentieri CAI
                    ipos = ss.IndexOf('/');
                    s1 = ss.Substring(0, ipos);
                    words = s1.Split(delimiterChars0);
                    width = float.Parse(words[0], nfi);
                    dashValues[0] = 0F;
                    break;
                case 43:        //  sentieri
                case 44:        //  bordo di rotabile
                case 60:        //  tracce sentieri                    
                    ipos = ss.IndexOf('/');
                    s1 = ss.Substring(0, ipos);
                    words = s1.Split(delimiterChars0);
                    width = float.Parse(words[2], nfi);
                    dashValues[0] = float.Parse(words[0], nfi);
                    dashValues[1] = float.Parse(words[1], nfi);
                    break;
                default:
                    width = 0F;
                    break;
            }
            if (width == 0F) goto L40;
            /*        
                    if (vectS[pntSimb].penType == 1)
                    {
                        width = float.Parse(ss);
                    }
                    //            float width = vectS[pntSimb].penWidth;
                    */

            Pen iPen = new Pen(icolor, width);
            if (type != 12 && dashValues[0] > 0F) iPen.DashPattern = dashValues;

            Point[] polygon = new Point[nVertices];
            for (int j = 0; j < nVertices; ++j)
            {
                polygon[j].X = (int)((ViewQ.PL[ipnt].X - ViewQ.Xmin) * ViewQ.scalaX) + ViewQ.Xoff;
                polygon[j].Y = (int)((ViewQ.PL[ipnt].Y - ViewQ.Ymin) * ViewQ.scalaY) + ViewQ.Yoff;
                ++ipnt;
                Rectangle pntR = new Rectangle(polygon[j].X, polygon[j].Y, 4, 4);
                if (type != 12) ViewQ.dc0.DrawEllipse(iPen, pntR);
            }
            if (type == 11 || type == 12 || type == 13)            // scarpata (piede)
            {
                scr.scarpata(iPen, polygon, width, dashValues[0], dashValues[1], interpasso, ViewQ.dc0, ipt, type);
            }

            else if (type == 38)    //  limite di comune
            {
                dashValues[0] = diam;
                dashValues[1] = interpasso - diam;
                iPen.DashPattern = dashValues;
                ViewQ.dc0.DrawCurve(iPen, polygon);
            }

            else ViewQ.dc0.DrawCurve(iPen, polygon);

            if (type == 26 && diam > 0)        //  limite di bosco
            {
        //        scr.limiteDiBosco(iPen, polygon, width, dashValues[0], dashValues[1], interpasso, diam, dc0, ipt);
            }

        L40: ;
            ViewQ.dc0.ResetTransform();

            }
        }
        
}
